package app.modules.cloudpivot.authentication;

import java.util.ArrayList;
import java.util.List;

import org.springframework.http.HttpRequest;

import com.authine.cloudpivot.platform.integration.AdapterConfigParam;
import com.authine.cloudpivot.platform.integration.AdapterConfigParam.Auth;
import com.authine.cloudpivot.platform.integration.RestAuthenticationSetting;
import com.authine.cloudpivot.platform.integration.auth.RestAuthenticationService;

public class CustomAuthenticationServiceImpl implements RestAuthenticationService {

    @Override
    public Auth getAuthConfig() {
        /* 定义鉴权信息 */
        List<AdapterConfigParam.Param> params = new ArrayList<>();
        params.add(new AdapterConfigParam.Param("ak", "AK", "AK", true));
        params.add(new AdapterConfigParam.Param("sk", "SK", "SK", true));
        return new AdapterConfigParam.Auth("custom_auth", "自定义鉴权", "自定义鉴权 用于演示", params);
    }

    @Override
    public HttpRequest getAuthenticatedRequest(RestAuthenticationSetting setting, HttpRequest request) {
        /* 获取鉴权设置的参数 */
        String ak = setting.getAuthParams().get("ak");
        String sk = setting.getAuthParams().get("sk");
        request.getHeaders().add("ak", ak);
        request.getHeaders().add("sk", sk);
        return request;
    }
}
